package com.cosina.game.robodefence.util;

public class CycleCount {
	private final int max ;
	public CycleCount(int max){
		if(max < 0){
			throw new IllegalArgumentException("cycle must more than zero");
		}
		this.max = max;
	}
	
	public int value = 0; 
	
	public boolean add = true; 
	
	public void doCycle(){
		doCycle(1);
	}
	
	public void doCycle(int size){
		if(add){
			value += size;
			if(value >= max){
				add = false;
				value =  2*max - value;
			}
		}else{
			value -= size;
			if(value <= 0){
				add = true;
				value =  0 - value;
			}
		}
	}
}
